package com.hhl.jni.threadpool;

import com.hhl.jni.thread.MyThread;

public class TaskThreadPoolApplication {
    public static MyTaskThreadPool threadPool;

    /**
     * 我是工作线程task_pool
     * replaceClassName = com/hhl/jni/thread/MyThread
     * 2068526848: 成功将任务加入任务池: current=0, size=1, max_size=4
     * 1492915968: 该线程抢到了任务，开始执行: current=0, size=1, max_size=4
     * Thread-0 say: 0
     * Thread-0 say: 1
     * Thread-0 say: 2
     * Thread-0 say: 3
     * Thread-0 say: 4
     * Thread-0 say: 5
     * Thread-0 say: 6
     * Thread-0 say: 7
     * Thread-0 say: 8
     * Thread-0 say: 9
     *
     *
     *
     * 我是工作线程task_pool
     * -603982080: 当前无可执行任务，阻塞，等待调度: current=0, size=0, max_size=4
     * 我是工作线程task_pool
     * -612374784: 当前无可执行任务，阻塞，等待调度: current=0, size=0, max_size=4
     * replaceClassName = com/hhl/jni/thread/MyThread
     * 900589312: 成功将任务加入任务池: current=0, size=1, max_size=4
     * -603982080: 该线程抢到了任务，开始执行: current=0, size=1, max_size=4
     * Thread-0 say: 0
     * Thread-0 say: 1
     * Thread-0 say: 2
     * Thread-0 say: 3
     * Thread-0 say: 4
     * Thread-0 say: 5
     * Thread-0 say: 6
     * Thread-0 say: 7
     * Thread-0 say: 8
     * Thread-0 say: 9
     * @param args
     */
    public static void main(String[] args) {
        System.loadLibrary("taskthreadpool");
        threadPool = new MyTaskThreadPool();

        threadPool.init(2,5,4);
        /**
         * 因为JNI的FindClass接收的参数格式是java/lang/String，JNI转换较麻烦，在Java中转换
         */
        String replaceClassName = MyThread.class.getName().replace('.', '/');
        System.out.println("replaceClassName = " + replaceClassName);
        threadPool.addTask(replaceClassName);
        threadPool.destroy();
    }
}
